// PrPageGeneral.cpp : implementation file
//

#include "stdafx.h"
#include "ansieditor.h"
#include "PrPageGeneral.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPrPageGeneral dialog


CPrPageGeneral::CPrPageGeneral(CWnd* pParent /*=NULL*/)
	: CPrPage(CPrPageGeneral::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPrPageGeneral)
	m_nPageHeight = 0;
	m_nPageWidth = 0;
	m_nMRUCount = 0;
	m_bAutoSizeNotAe3Doc = FALSE;
	m_bSaveRecover = FALSE;
	m_nSaveRecoverInterval = 60;
	//}}AFX_DATA_INIT
}


void CPrPageGeneral::DoDataExchange(CDataExchange* pDX)
{
	CPrPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPrPageGeneral)
	DDX_Control(pDX, IDC_CHK_SAVE_RECOVER, m_chkSaveRecover);
	DDX_Control(pDX, IDC_TXT_SAVE_RECOVER_INTERVAL, m_txtSaveRecoverInterval);
	DDX_Control(pDX, IDC_SPN_SAVE_RECOVER_INTERVAL, m_spnSaveRecoverInterval);
	DDX_Control(pDX, IDC_SPIN_WIDTH, m_spinPageWidth);
	DDX_Control(pDX, IDC_SPIN_HEIGHT, m_spinPageHeight);
	DDX_Control(pDX, IDC_SPIN_MRUCOUNT, m_spinMRUCount);
	DDX_Text(pDX, IDC_EDIT_HEIGHT, m_nPageHeight);
	DDV_MinMaxInt(pDX, m_nPageHeight, 1, 65535);
	DDX_Text(pDX, IDC_EDIT_WIDTH, m_nPageWidth);
	DDV_MinMaxInt(pDX, m_nPageWidth, 1, 512);
	DDX_Text(pDX, IDC_TXT_MRUCOUNT, m_nMRUCount);
	DDV_MinMaxInt(pDX, m_nMRUCount, 1, 16);
	DDX_Check(pDX, IDC_CHK_AUTOSIZE_NOTAE3DOC, m_bAutoSizeNotAe3Doc);
	DDX_Check(pDX, IDC_CHK_SAVE_RECOVER, m_bSaveRecover);
	DDX_Text(pDX, IDC_TXT_SAVE_RECOVER_INTERVAL, m_nSaveRecoverInterval);
	DDV_MinMaxUInt(pDX, m_nSaveRecoverInterval, 1, 3600);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPrPageGeneral, CPrPage)
	//{{AFX_MSG_MAP(CPrPageGeneral)
	ON_BN_CLICKED(IDC_CHK_SAVE_RECOVER, OnChkSaveRecover)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPrPageGeneral message handlers

BOOL CPrPageGeneral::OnInitDialog() 
{
	m_nPageWidth = gpApp->m_options.nPageWidth;
	m_nPageHeight = gpApp->m_options.nPageHeight;
	m_nMRUCount = gpApp->m_options.nMRUCount;
	m_bAutoSizeNotAe3Doc = gpApp->m_options.bAutoSizeNotAe3Doc;
	m_bSaveRecover = gpApp->m_options.bSaveRecover;
	m_nSaveRecoverInterval = gpApp->m_options.nSaveRecoverInterval;
	
	CPrPage::OnInitDialog();

	m_spinPageWidth.SetRange32(1, 512);
	m_spinPageHeight.SetRange32(1, 65535);
	m_spinMRUCount.SetRange32(1, 16);

	m_spnSaveRecoverInterval.SetRange32(1, 3600);
	OnChkSaveRecover();
	
	return TRUE;
}

BOOL CPrPageGeneral::ValidateData()
{
	UpdateData();
	BOOL bUpdateMRUCount = FALSE;
	if(gpApp->m_options.nMRUCount != m_nMRUCount)
	{
		bUpdateMRUCount = TRUE;
	}
	BOOL bUpdateSaveRecover = gpApp->m_options.bSaveRecover != m_bSaveRecover;
	bUpdateSaveRecover |= m_bSaveRecover && (gpApp->m_options.nSaveRecoverInterval != m_nSaveRecoverInterval);

	gpApp->m_options.nPageWidth = m_nPageWidth;
	gpApp->m_options.nPageHeight = m_nPageHeight;
	gpApp->m_options.nMRUCount = m_nMRUCount;
	gpApp->m_options.bAutoSizeNotAe3Doc = m_bAutoSizeNotAe3Doc;
	gpApp->m_options.bSaveRecover = m_bSaveRecover;
	gpApp->m_options.nSaveRecoverInterval = m_nSaveRecoverInterval;

	if(bUpdateMRUCount)
	{
		gpApp->UpdateMRUCount();
	}
	if(bUpdateSaveRecover)
	{
		gpFrame->SetSaveRecoverTimer();
	}
	return CPrPage::ValidateData();
}

void CPrPageGeneral::OnChkSaveRecover() 
{
	BOOL bEnable = m_chkSaveRecover.GetCheck();
	m_txtSaveRecoverInterval.EnableWindow(bEnable);
	m_spnSaveRecoverInterval.EnableWindow(bEnable);
}
